<?php


namespace app\model;


use think\Model;
use utils\Define;

class Advertising extends Model
{

    /**
     * 轮播图
     * @param $type
     * @return mixed
     */
    public function banner($type)
    {
        try {
            $result = $this->
            where(['type' => $type, 'status' => 1])
                ->field('id,title,image,created_time,type')
                ->withAttr('type', function ($value, $data) {
                    return self::type($value);
                })
                ->order('sort desc')
                ->select()
                ->toArray();
            return app('json')->json_success('成功', $result);
        } catch (\Exception $e) {
            return app('json')->json_error('获取失败 ' . $e->getMessage());
        }
    }


    /**
     * 类型
     * @param $type
     * @return string
     */
    public static function type($type)
    {
        $type = Define::BannerType[$type] ?: '';
        return $type;
    }
}